<template>
  <div class="frame-page">
    <div class="h-panel">
      <div class="h-panel-body">
        <Form  class="mt-16px w-400px"  ref="form" :labelWidth="100" :model="store" :rules="validationRules">
          <FormItem label="编码" prop="code" required>
            <Input v-model="store.code" readonly/>
          </FormItem>
          <FormItem label="名称" prop="name" required>
            <Input v-model="store.name" />
          </FormItem>
          <FormItem label="联系人" required prop="linkman">
            <Input placeholder="请输入门店联系人" v-model="store.linkman"/>
          </FormItem>
          <FormItem label="联系人电话" required prop="phone">
            <Input placeholder="请输入联系人手机号" v-model="store.phone"/>
          </FormItem>
          <FormItem label="类型" prop="type">
            <Radio v-model="store.type" :datas="{0:'直营',1:'加盟'}"></Radio>
          </FormItem>
          <FormItem label="邮箱" prop="email">
            <Input placeholder="请输入邮箱" v-model="store.email"/>
          </FormItem>
          <FormItem label="地址" prop="address">
            <Input placeholder="请输入地址" v-model="store.address"/>
          </FormItem>
          <FormItem>
            <Button @click="doSave" :loading="loading" icon="fa fa-save" color="primary">保 存</Button>
          </FormItem>
        </Form>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from "vuex";
import Organization from "@js/api/Organization";
import {message} from "heyui";
import {clone} from "xe-utils";

/**
 * @功能描述: 机构信息
 * @创建时间: 2023年08月08日
 * @公司官网: www.fenxi365.com
 * @公司信息: 纷析云（杭州）科技有限公司
 * @公司介绍: 专注于财务相关软件开发, 企业会计自动化解决方案
 */
export default {
  name: "OrganizationView",
  data() {
    return {
      loading: false,
      initLoading: false,
      storeList: [],
      store: {},
      validationRules: {
        mobile: ['phone']
      }
    }
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    doSave() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        this.loading = true;
        Organization.save(this.store).then(() => {
          message("保存成功,重新登录后生效~");
        }).finally(() => this.loading = false);
      }
    },
  },
  created() {
    this.store = clone(this.user.organization, true);
  }
}
</script>

<style scoped>

</style>